<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算机练习</title>
</head>
<body>
<input type="text" id="s1" placeholder="请输入数字1"><br>
<input type="text" id="s2" placeholder="请输入数字1"><br>
<button onclick="f('+')">加</button>
<button onclick="f('-')">减</button>
<button onclick="f('*')">乘</button>
<button onclick="f('/')">除</button>
运算结果:<span id="span"></span>

<script>
    function f(n) {
        var s1 = document.getElementById('s1').value;
        var s2 = document.getElementById('s2').value;
        s1 = parseFloat(s1);
        s2 = parseFloat(s2);
         var elementById = document.getElementById('span');
        console.log(fuhao)
        switch (n) {
            case '+':
                elementById.innerHTML = s1 + s2;
                break;
            case '-':
                elementById.innerHTML = s1 - s2;
                break;
            case '*':
                elementById.innerHTML = s1 * s2;
                break;
            case '/':
                if (s2 == 0) {
                    alert('被除数不能为0')
                } else {
                    elementById.innerHTML = s1 / s2;
                }
                break;


        }


    }

</script>
</body>
</html>